using Godot;
using System;

public partial class Silk : AnimatedSprite2D
{
	public Enemy enemy;

	public Player player;

	public Area2D area2D;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		Visible = false;
		
		enemy = GetNode<Enemy>("/root/Main/Enemy");

		player = GetNode<Player>("//root/Main/Player");

		AnimationFinished+=OnThrowSilkFinished;

		area2D = GetNode<Area2D>("Area2D");
		area2D.BodyEntered+=OnCollision;
		area2D.SetCollisionMaskValue(2,false);
	}

    private void OnCollision(Node2D body)
    {
        if(body.Name == "Player")
		{
			GD.Print($"silk collide player");
			player.OnHurt();
		}
    }


    private void OnThrowSilkFinished()
    {
        Visible = false;
		area2D.SetCollisionMaskValue(2,false);
    }


    public void OnThrowSilk()
	{
		Visible = true;
		area2D.SetCollisionMaskValue(2,true);
		GetNode<AudioStreamPlayer2D>("Music").Play();
		Play();	
	}
}
